package org.filehanding.vo;

/**
 * Created by liguo on 2016/5/14.
 */
public class ResponseValue {
    public static final int RESPONSE_CODE_SUCCESS = 200;
    public static final int RESPONSE_CODE_NO_CONTENT = 204;
    public static final int RESPONSE_CODE_NOT_FOUND = 404;
    public static final int RESPONSE_CODE_NOT_ACCEPT = 406;
    public static final int RESPONSE_CODE_FAIL = 500;
    public static final int RESPONSE_CODE_NO_PERMISSION = 403;
    public static final int RESPONSE_CODE_DENY_ACCESS = 401;

    private int code;
    private String message = "";
    private Object result = "";

    public ResponseValue() {
        this.code = RESPONSE_CODE_SUCCESS;
    }

    public ResponseValue(int code) {
        this.code = code;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public static String getResponseMessage(int code) {
        String message = "未知错误";
        switch (code) {
            case RESPONSE_CODE_SUCCESS:
                message = "成功";
                break;
            case RESPONSE_CODE_NO_CONTENT:
                message = "没有请求内容";
                break;
            case RESPONSE_CODE_NOT_FOUND:
                message = "未发现客户端请求内容";
                break;
            case RESPONSE_CODE_NOT_ACCEPT:
                message = "服务器不接受此类请求";
                break;
            case RESPONSE_CODE_FAIL:
                message = "服务器内部错误";
                break;
            case RESPONSE_CODE_NO_PERMISSION:
                message = "没有操作权限";
                break;
            case RESPONSE_CODE_DENY_ACCESS:
                message = "服务器拒绝访问";
                break;
            default:
                break;
        }
        return message;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ResponseValue that = (ResponseValue) o;

        if (code != that.code) return false;
        if (message != null ? !message.equals(that.message) : that.message != null) return false;
        if (result != null ? !result.equals(that.result) : that.result != null) return false;

        return true;
    }


    @Override
    public int hashCode() {
        int result = code;
        result = 31 * result + (message != null ? message.hashCode() : 0);
        result = 31 * result + (this.result != null ? this.result.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "{" +
                "code:" + code +
                ", message:'" + message + '\'' +
                ", result:" + result +
                '}';
    }
}
